package commands;

import core.Card;
import core.Visibility;

/**
 * A <code>Command</code> that changes one <code>Card</code>'s <code>Visibility</code>.
 */
public class ChangeVisibilityCommand extends CardCommand
{
	public ChangeVisibilityCommand() {
		this(null, null);
	}

	public ChangeVisibilityCommand(Card card, Visibility visibility) {
		super(card);
		setVisibility(visibility);
	}

	public net.StateUpdate execute() throws CommandException {
		if (card == null)
			throw new CommandException(this, "null card in ChangeVisibilityCommand");
		net.StateUpdate stateUpdate = super.execute();
		core.Card newCard = new core.Card(card);
		newCard.setVisibility(visibility);
		stateUpdate.addChange(new net.ChildRemoval(card.getZone(), "card", card));
		stateUpdate.addChange(new net.ChildAddition(card.getZone(), "card", newCard));
		return stateUpdate;
	}

	public void setCard(core.Card card) {
		super.setCard(card);
		oldVisibility = (card == null ? null : card.getVisibility());
	}

	public Visibility getVisibility() {
		return visibility;
	}

	public void setVisibility(Visibility visibility) {
		this.visibility = visibility;
	}

	public String getMessage() {
		return "change visibility of " + util.Util.prettyPrint(card) + " from " + oldVisibility + " to " + visibility;
	}

	private Visibility visibility, oldVisibility;
}
